package com.hzz.common.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


public class PreferenceUtil {
    private static SharedPreferences mSp;
    private static Editor mEditor;

    public static void init(Context context) {
        mSp = context.getSharedPreferences("Axin", Context.MODE_PRIVATE);
        mEditor = mSp.edit();
    }

    /**
     * 取出String
     */
    public static String getString(String key, String defValue) {
        return mSp.getString(key, defValue);
    }

    /**
     * 取出Int
     */
    public static int getInt(String key, int defValue) {
        return mSp.getInt(key, defValue);
    }

    /**
     * 取出Boolean
     */
    public static boolean getBoolean(String key, boolean defValue) {
        return mSp.getBoolean(key, defValue);
    }

    /**
     * 存入String
     */
    public static void putString(String key, String value) {
        mEditor.putString(key, value);
        mEditor.commit();
    }

    /**
     * 存入Int
     */
    public static void putInt(String key, int value) {
        mEditor.putInt(key, value);
        mEditor.commit();
    }

    /**
     * 存入Boolean
     */
    public static void putBoolean(String key, boolean value) {
        mEditor.putBoolean(key, value);
        mEditor.commit();
    }

    public static void putLong(String key, long value) {
        mEditor.putLong(key, value);
        mEditor.commit();
    }

    public static long getLong(String key, long defValue) {
        return mSp.getLong(key, defValue);
    }

    /**
     * 清空保存
     */
    public static void clearAll() {
        mEditor.clear();
        mEditor.commit();
    }
}
